<script lang="ts" setup>
import type { Rule } from 'ant-design-vue/es/form';

import { ref } from 'vue';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { Form, Input, Select } from 'ant-design-vue';

import { $t } from '#/locales';

// 创建本地数据副本
const modelData = defineModel<any>();
// 表单引用
const formRef = ref();
const rules: Record<string, Rule[]> = {
  code: [{ required: true, message: $t('views.ai.workflow.codeRequired'), trigger: 'blur' }],
  name: [{ required: true, message: $t('views.ai.workflow.nameRequired'), trigger: 'blur' }],
  status: [{ required: true, message: $t('views.ai.workflow.statusRequired'), trigger: 'change' }],
};

/** 表单校验 */
async function validate() {
  await formRef.value?.validate();
}

defineExpose({ validate });
</script>

<template>
  <Form
    ref="formRef"
    :model="modelData"
    :rules="rules"
    :label-col="{ span: 4 }"
    :wrapper-col="{ span: 20 }"
    class="mt-5"
  >
    <Form.Item :label="$t('views.ai.workflow.code')" name="code" class="mb-5">
      <Input
        class="w-full"
        v-model:value="modelData.code"
        allow-clear
        :placeholder="$t('views.ai.workflow.codePlaceholder')"
      />
    </Form.Item>
    <Form.Item :label="$t('views.ai.workflow.name')" name="name" class="mb-5">
      <Input
        v-model:value="modelData.name"
        allow-clear
        :placeholder="$t('views.ai.workflow.namePlaceholder')"
      />
    </Form.Item>
    <Form.Item :label="$t('common.status')" name="status" class="mb-5">
      <Select
        class="w-full"
        v-model:value="modelData.status"
        allow-clear
       :placeholder="$t('common.statusPlaceholder')"
      >
        <Select.Option
          v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS, 'number')"
          :key="dict.value"
          :value="dict.value"
        >
          {{ dict.label }}
        </Select.Option>
      </Select>
    </Form.Item>
    <Form.Item :label="$t('views.ai.workflow.description')" name="description" class="mb-5">
      <Input.TextArea 
        v-model:value="modelData.description" 
        allow-clear 
        :placeholder="$t('views.ai.workflow.descriptionPlaceholder')"
        />
    </Form.Item>
  </Form>
</template>
